package org.ben.threadpool;

import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class ThreadPoolTest {
    public static ThreadPoolExecutor executor = new ThreadPoolExecutor(3,3,100,TimeUnit.SECONDS,
            new LinkedBlockingQueue<Runnable>(100));

    public static void main(String[] args) {
        for(int i = 0; i < 100; i++) {
            executor.execute(new WorkerThread(i+" running..."));
        }
        Executors.newCachedThreadPool();
        try {
            Thread.sleep(10000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        executor.shutdown();
    }
}

class WorkerThread implements Runnable {
    private String command;

    WorkerThread(String cmd) {
        this.command = cmd;
    }

    public void run() {
        System.out.println(this.command);
    }
}
